package com.lu.controller;

import com.lu.dto.BlogDTO;
import com.lu.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by lulu on 2017/8/30.
 */
@RequestMapping("myblog")
@Controller
public class BlogController {
    @Autowired
    BlogService blogService;

    @RequestMapping("index.html")
    public String index() {
        return "index";
    }

    @RequestMapping("allblog.html")
    public String getAllBlog(@RequestParam(required = false) String key, Model model) {
        List<BlogDTO> list = blogService.getBlog(key);
        if (list == null || list.size() == 0) {
            return "fail";
        }
        model.addAttribute("listblog", list);
        return "index";
    }

    @RequestMapping("detail.html")
    public String getBlogById(int id, Model model) {
        BlogDTO blogDTO = blogService.getBlogById(id);
        if (blogDTO == null) {
            return "false";
        }
        model.addAttribute("blog", blogDTO);
        return "detail";
    }

    @RequestMapping("addlikecount")
    //这里返回如何渲染页面？   如何拿到id？
    public String addLikeCount(int id) {
        blogService.addLikeCount(id);
        return "detail";//
    }
}
